package net.hn.hnms.biz.process.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.hn.hnms.biz.process.domain.JobProcess;
import net.hn.hnms.biz.process.domain.StandardProcess;
import net.hn.hnms.biz.process.domain.vo.JobProcessVo;
import net.hn.hnms.biz.process.domain.vo.StandardProcessVo;
import net.hn.hnms.biz.process.mapper.JobProcessMapper;
import net.hn.hnms.biz.process.mapper.StandardProcessMapper;
import net.hn.hnms.biz.process.service.StandardProcessService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.exception.ServiceException;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class StandardProcessServiceImpl extends ServiceImpl<StandardProcessMapper, StandardProcess> implements StandardProcessService {


    @Resource
    private JobProcessMapper jobProcessMapper;

    @Override
    public int insert(StandardProcess standardProcess) {
        return baseMapper.insert(standardProcess);
    }

    @Override
    public void deleteBatch(List<String> idList) {
        baseMapper.deleteBatchIds(idList);
    }

    @Override
    public StandardProcessVo selectDetailById(String id) {
        StandardProcess standardProcess = baseMapper.selectById(id);
        if (standardProcess != null) {
            StandardProcessVo standardProcessVo = BeanUtil.copyProperties(standardProcess, StandardProcessVo.class);
            JobProcess jobProcess = jobProcessMapper.selectById(standardProcess.getProcessId());
            if (jobProcess != null) {
                standardProcessVo.setProcessName(jobProcess.getProcessName());
                standardProcessVo.setPositionName(jobProcess.getPositionName());
            }
        }
        throw new ServiceException("数据不存在");
    }

    @Override
    public ResponsePage<StandardProcessVo> selectPageList(StandardProcessVo standardProcessVo, PageQuery pageQuery) {
        Page<StandardProcessVo> page = baseMapper.select(pageQuery.build(),standardProcessVo);
        return new ResponsePage<>(page.getRecords(), page.getTotal());
    }

}
